use rand::Rng;
use std::cmp::Ordering;
use std::io;
use std::{thread, time};
use std::fmt::Debug;
use std::net::{IpAddr, Ipv4Addr};


// Debug输出格式, Debug是一个trait, derive增加派生Debug trait
#[derive(Debug)]
enum IpAddrKind {
    V4(String),
    V6(String),
}

#[derive(Debug)]
enum IpAddrArgs {
    V4(u8, u8, u8, u8),
    V6(String),
}

#[derive(Debug)]
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}

impl Message {
    fn call(&self) {
        println!("{:#?} in call do somethings.", &self);
    }
}


pub fn enumsArgs() {
    println!("#################################");
    println!("##      enumsArgs                 ");
    println!("#################################");
    println!("simpleFn.");

    // IpAddr::V4() 是一个获取 String 参数并返回 IpAddr 类型实例的函数调用
    let home = IpAddrKind::V4(String::from("127.0.0.1"));
    let loopback = IpAddrKind::V6(String::from("::1"));

    /*   格式化打印   */
    println!("enumsArgs IpAddrKind home is: {:#?}", home);
    println!("enumsArgs IpAddrKind loopback is: {:#?}", loopback);

    let home1 = IpAddrArgs::V4(127, 0, 0, 1);
    let loopback1 = IpAddrArgs::V6(String::from("::1"));
    println!("enumsArgs IpAddrArgs home1 is: {:#?}", home1);
    println!("enumsArgs IpAddrArgs loopback1 is: {:#?}", loopback1);

    // 标准库的 IpAddr 定义
    let home2 = IpAddr::V4(Ipv4Addr::from([127, 0, 0, 1]));
    println!("net::IpAddr home2 is: {:#?}", home2);

    let m: Message = Message::Write(String::from("hello"));
    m.call();
}
